import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class 模板最小生成树 {
    /**
     *     依靠并查集
     *     https://www.luogu.com.cn/problem/P3366
     */
    public static int MAXN = 5001;
    public static int MAXM = 200001;
    public static int[][] edges = new int[MAXM][3];
    public static int[] farther = new int[MAXN];
    public static int n;
    public static int m;
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static void main(String[] args) throws IOException{
        n = in.nextInt();
        m = in.nextInt();
        //遍历即可, 不需要用建图的方式存储
        for (int i = 0; i < m; i++) {
            edges[i][0] = in.nextInt();
            edges[i][1] = in.nextInt();
            edges[i][2] = in.nextInt();
        }
        //按权值大小进行排序
        Arrays.sort(edges,0,m,(x,y) -> x[2] - y[2]);
        build();
        //最小生成树边的数量是点的数量减1
        int edgeCnt = 0;//边的数量
        int ans = 0;
        for (int i = 0; i < m; i++) {
            //每次加入并查集,将连成线的点
            if(union(edges[i][0],edges[i][1])){
                edgeCnt++;
                ans += edges[i][2];
            }
        }
        out.println(edgeCnt == n - 1 ? ans : "orz");
        out.close();
    }

    private static void build() {
        for (int i = 1; i <= n; i++) {
            farther[i] = i;
        }
    }

    private static int find(int n){
        if(farther[n] != n){
            farther[n] = find(farther[n]);
        }
        return farther[n];
    }

    private static boolean union(int x,int y){
        int fx = find(x);
        int fy = find(y);
        if(fx != fy){
            farther[fx] = fy;
            return true;
        }else{
            return false;
        }
    }
    public static class Read{
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException{
            while(!st.hasMoreTokens()){
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}
